﻿using System;
using SKQMSLib;

namespace ConsoleGUI
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                bool digitGrouping = true;
                //draw menu
                Console.WriteLine("Enter \"exit\" to exit.");
                Console.WriteLine("Enter \"clr\" to clear the console.");
                Console.WriteLine("Enter \"dgon\" or \"dgoff\" to enable or disable digit grouping.");
                Console.WriteLine();

                if (digitGrouping) Console.WriteLine("Digit grouping is ON.");
                else Console.WriteLine("Digit grouping is OFF.");
                Console.WriteLine("Enter the equations below:" + Environment.NewLine);

                while (true)
                {
                    string userInput = Console.ReadLine();
                    
                    if (userInput == "exit") break;
                    if (userInput == "dgon")
                    { 
                        digitGrouping = true; 
                        Console.WriteLine("Digit grouping is ON." + Environment.NewLine); 
                        continue; 
                    }
                    if (userInput == "dgoff")
                    { 
                        digitGrouping = false;
                        Console.WriteLine("Digit grouping is OFF." + Environment.NewLine); 
                        continue; 
                    }
                    if (userInput == "clr")
                    {
                        Console.Clear();
                        //draw menu
                        Console.WriteLine("Enter \"exit\" to exit.");
                        Console.WriteLine("Enter \"clr\" to clear the console.");
                        Console.WriteLine("Enter \"dgon\" or \"dgoff\" to enable or disable digit grouping.");
                        Console.WriteLine();

                        if (digitGrouping) Console.WriteLine("Digit grouping is ON."); 
                        else Console.WriteLine("Digit grouping is OFF.");
                        Console.WriteLine("Enter the equations below:" + Environment.NewLine);
                        continue;
                    }
                    //calculate & display solution
                    LinearAlgebraicEquation equation = new LinearAlgebraicEquation(userInput);
                    Console.WriteLine();
                    Console.WriteLine("The solution is: " + equation.GetSolution(digitGrouping));
                    Console.WriteLine();
                }
            }
            catch (InvalidSignPositionException ex) { Console.WriteLine(); Console.WriteLine(ex.Message); Console.WriteLine(); Console.ReadLine(); }
            catch (UnkownCharacterException ex) { Console.WriteLine(); Console.WriteLine(ex.Message); Console.WriteLine(); Console.ReadLine(); }
            catch (NumberOutOfBoundsException ex) { Console.WriteLine(); Console.WriteLine(ex.Message); Console.WriteLine(); Console.ReadLine(); }
            catch (ParenthesisException ex) { Console.WriteLine(); Console.WriteLine(ex.Message); Console.WriteLine(); Console.ReadLine(); }
            catch (UnknownRelatedException ex) { Console.WriteLine(); Console.WriteLine(ex.Message); Console.WriteLine(); Console.ReadLine(); }
            catch (DivideByZeroException ex) { Console.WriteLine(); Console.WriteLine(ex.Message); Console.WriteLine(); Console.ReadLine(); }
        }
    }
}
